package com.boot_reggie.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result <T>{
    private Integer code; //编码成功为1，错误为0和其他数字
    private String msg; //错误消息
    private T data; //数据
    private Map map = new HashMap();//动态数据
    public static <T> Result<T> success(String msg){
        Result<T> result = new Result<T>();

        result.code = 1;
        result.msg = msg;
        return result;
    }
    public static <T> Result<T> success(T obj,String msg){
        Result<T> result = new Result<T>();
        result.data = obj;
        result.code = 1;
        result.msg = msg;
        return result;
    }
    public static <T> Result<T> error(String msg){
        Result<T> result = new Result<T>();
        result.code = 0;
        result.msg = msg;
        return result;
    }
    public Result<T> add(String key,Object value){
        this.map.put(key,value);
        return this;
    }
//    未登录
    public static <T>Result<T> Nulllogin (){
        Result<T> result = new Result<T>();
        result.code = 401;
        result.msg = "未登录!";
        return result;
    }
//    分页查询的数据
    public static <IPage>Result<IPage> pageData(IPage iPage){
        Result<IPage> result = new Result<IPage>();
        result.code =1;
        result.msg="数据查询成功";
        result.data = iPage;
        return result;
    }
//    无权限
    public static Result<String> kwone(){
        Result<String> result = new Result<>();
        result.code = 0;
        result.msg="无权限可操作";
        return result;
    }
}
